﻿<html><head>
<LINK rel=stylesheet type=text/css href="css/ui.css">
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title></title>
</head>
<body>
<script language="JavaScript"> 
<!--

var p_picture;
var p_albumtitle;
var p_company;
var p_rating_avg;
var p_public_time;
var p_album;
var p_like;
var p_artist;
var p_url;
var p_title;
var p_length;
var p_info;
var p_swich=true;
var p_channel=5;

window.onload = function () { setInterval ('initProc ()', 500); }
var tid = 0;
var p_next = 0;
var p_result ;
function timeoutProc () {
    clearTimeout (tid);
    tid = 0;
    var status = psp.sysRadioGetHttpGetStatus ();
    switch ( status ) {
    case 0:
        var result = psp.sysRadioGetHttpGetResult ();
        p_result =  result;
        psp.sysRadioHttpGetTerminate ();
        sysRadio_Start(Trim(Convert .StringToJSON(result).song[p_next].url));
        ui_Start(Trim(Convert .StringToJSON(result).song[p_next].picture));
        DoCallTimerStop();
        DoCallTimer();   
        p_title.innerHTML = Trim(Convert .StringToJSON(result).song[p_next].title);
        p_albumtitle.innerHTML = Trim(Convert .StringToJSON(result).song[p_next].artist) + " - ";
        p_album.href="http://music.douban.com" + Trim(Convert .StringToJSON(result).song[p_next].album);
        var albumWidh = document.getElementById("namealbum").offsetWidth+229+"px";
        p_artist.style.left=albumWidh;
        p_artist.innerHTML = Trim(Convert .StringToJSON(result).song[p_next].albumtitle);
    
        break;
    case 1:
        tid = setTimeout ('timeoutProc ()', 1000);
        break;
    default: 
        psp.sysRadioHttpGetTerminate ();
        break;
    }
}

function test () {
  p_swich=true;
  p_length=document.getElementById("time");
  p_picture=document.getElementById("albumThumbnail");
  p_info=document.getElementById("info");
  p_title=document.getElementById("title");
  p_albumtitle=document.getElementById("namealbum");
  p_artist=document.getElementById("dbname");
  p_album=document.getElementById("dburl");
    psp.sysRadioPrepareForHttpGet
        ("http://douban.fm/j/mine/playlist?type=n&channel="+p_channel);
    if (tid == 0 ) tid = setTimeout ('timeoutProc ()', 500);
}

var Convert = {
    StringToJSON: function(str) {
        var a;
        eval('a=' + str + ';');
        return a; 
    },
    ToJSONString: function(obj) {
        switch(typeof(obj)) 
        {
            case 'object':
                var ret = [];
                if (obj instanceof Array) 
                {
                    for (var i = 0, len = obj.length; i < len; i++) 
                    {
                        ret.push(Convert.ToJSONString(obj[i]));
                    }
                    return '[' + ret.join(',') + ']';
                } 
                else if (obj instanceof RegExp) 
                {
                    return obj.toString();
                } 
                else 
                {
                    for (var a in obj) 
                    {
                        ret.push(a + ':' + Convert.ToJSONString(obj[a]));
                    }
                    return '{' + ret.join(',') + '}';
                }
            case 'function':
                return 'function() {}';
            case 'number':
                return obj.toString();
            case 'string':
                return "\"" + obj.replace(/(\\|\")/g, "\\$1").replace(/\n|\r|\t/g, function(a) {return ("\n"==a)?"\\n":("\r"==a)?"\\r":("\t"==a)?"\\t":"";}) + "\"";
            case 'boolean':
                return obj.toString();
            default:
                return obj.toString();
            
        }
    }
};

function sysRadio_Start(mp3url){
    //psp.sysRadioPlayEffectSound();
    psp.sysRadioPlayStream(mp3url, "PSP-InternetRadioPlayer/1.00");
    psp.sysRadioSetMasterVolume(255);
    psp.sysRadioSetSubVolume(255);
} 

function Trim(str) {
    var ret = "";
    var arr = str.toString().split(' ');
    if (arr.length > 1) {
        for (var i = 0; i < arr.length; i++) {
            ret += arr[i];
        }
    }
    else if (arr.length == 1) {
        ret = str;
    }
    return ret;
}

function initProc () {
    var status = psp.sysRadioGetPlayerStatus ();
    if(status==0&&p_swich)
    {
        if(p_next<Convert .StringToJSON(p_result).song.length-1)
        {
	    sleep(1);
            psp.sysRadioStop();
            DoCallTimerStop();
            p_next++;
            ui_Start(Trim(Convert .StringToJSON(result).song[p_next].picture));       
            p_title.innerHTML = Trim(Convert .StringToJSON(result).song[p_next].title);
            p_albumtitle.innerHTML = Trim(Convert .StringToJSON(result).song[p_next].artist) + " - ";
            p_album.href="http://music.douban.com" + Trim(Convert .StringToJSON(result).song[p_next].album);
            //
            var albumWidh = document.getElementById("namealbum").offsetWidth+229+"px";
            //
            p_artist.style.left=albumWidh;
            p_artist.innerHTML = Trim(Convert .StringToJSON(result).song[p_next].albumtitle);
            sysRadio_Start(Trim(Convert .StringToJSON(result).song[p_next].url));
            DoCallTimer();            
        }else
	    {
		sleep(1);
                p_next=0;
                test();
	    }
     }
}

function ui_Start(picurl){
    p_picture.src = picurl;
    p_picture.style.width = "121";
    p_picture.style.height = "121";
    p_info.src = "./pic/info_start.png";
    p_length.style.visibility = "visible"; 
    p_title.style.visibility = "visible";
    p_albumtitle.style.visibility = "visible";
    p_artist.style.visibility = "visible";
} 

var CallTimeLen = "-1";
var timer1 = null;

function DoCallTimer() {
  var minute=0;
  var second=-1;
    CallTimeLen = parseInt(CallTimeLen) + 1;
    minute = parseInt(CallTimeLen / 60);
    second = CallTimeLen % 60;
    if (minute == "0") {
        if (second < 10) {
            p_length.innerHTML = "00:0" + second;
        } else {
            p_length.innerHTML = "00:" + second;
        }
    }
    else {
        if (second < 10) {
            p_length.innerHTML = "0" + minute + ":0" + second;
        } else {
            if (minute < 10) {
                p_length.innerHTML = "0" + minute + ":" + second;
            } else {
                p_length.innerHTML = minute + ":" + second;
            }
        }
    }
    window.timer1 = window.setTimeout("DoCallTimer()", 1000);
}

function DoCallTimerStop() {
    CallTimeLen = "-1";
    clearTimeout(window.timer1);
}

function ui_Stop(){
    p_swich=false;
    p_picture.src = "./pic/albumThumbnail.png";
    p_picture.style.width = "144";
    p_picture.style.height = "144";
    p_info.src = "./pic/info_stop.png";
    p_length.style.visibility = "hidden";
    p_title.style.visibility = "hidden"; 
    p_albumtitle.style.visibility = "hidden";
    p_artist.style.visibility = "hidden";
    DoCallTimerStop();
    psp.sysRadioStop();
    psp.sysRadioPlayEffectSound();
}


function sleep(n) 
{ 
    var start=new Date().getTime(); 
    while(true) 
	if(new Date().getTime()-start>n) break; 
}  

function channelFun () {
    	index_gr = document.getElementById('genre').selectedIndex;
		search_genre = document.getElementById('genre').options[index_gr].text;
	p_channel=channel[index_gr];
	p_next=0;
	test();
}

var channel=new Array("4","1","2","3","4","5","6","7","8","9","10","13","14","15","16","17","18","20","22","23","26","27","28","29","30","31");


// -->
</script>

<object name="psp" type="application/x-psp-extplugin"></object>
<IMG id=bg border=0 src="pic/bg.png" width=480 height=272><IMG 
id=albumThumbnail src="pic/albumThumbnail.png" width=144 height=144><select id="genre" onchange='channelFun();'><option>Channel</option><option>华语MHz</option><option>欧美MHz</option><option>70MHz</option><option>80MHz</option><option>90MHz</option><option>粤语MHz</option><option>摇滚MHz</option><option>民谣MHz</option><option>轻音乐MHz</option><option>电影原声MHz</option><option>爵士MHz</option><option>电子MHz</option><option>说唱MHz</option><option>R&BMHz</option><option>日语MHz</option><option>韩语MHz</option><option>女声MHz</option><option>法语MHz</option><option>特仑苏MHz</option><option>豆瓣音乐人MHz</option><option>古典MHz</option><option>动漫MHz</option><option>PumaSocialMHz</option><option>BMW Club3MHz</option><option>NB敢动MHz</option></select><IMG 
id=switch src="pic/stop.png" onclick=ui_Stop(); width=23 height=23><IMG 
id=info src="pic/info_stop.png" width=232 height=43><IMG 
id=panel src="pic/controlpanel.png" width=146 height=49><IMG 
id=like src="pic/like0.png" width=42 height=42><IMG 
id=next src="pic/next0.png" onclick=test(); width=42 height=42>
<div id=time>00:00</div>
<div id=title>loading......</div>
<div id=namealbum>loading......</div><a href='' id=dburl><div id=dbname>loading......</div></a>
</body></html>
